<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        //固定加数加法柯里化
        const currying = fn =>{
            const fun = (...args) =>{
                if(args.length >= fn.length){
                    return fn(...args);
                }else{
                    return (...arg) => fun(...args, ...arg);
                }
            }
            return fun();
        }

        function add(a,b,c,d,e,f){
            return a+b+c+d+e+f;
        };

        // console.log(currying(add)(1,1)(2,2)(3,3));
        // console.log(add.length);

        //被减数和减数分开设置
        var curry = function(func){
             var args = [].slice.call(arguments,1); // 首先我们对通用函数截取参数
             return function(){
                 var newArgs = args.concat([].slice.call(arguments)); //将每次添加的函数连接起来
                 return func.apply(this,newArgs); //将此函数的数组赋给目标函数 并传入参数
             }
         }
         function sub(a,b){
             return a-b;
         }
         //设置被减数
         var subcurry_5 = curry(sub,5);

         //设置减数
         console.log(subcurry_5(1));

        
    </script>
</body>
</html>